package cau.se.project.unittest;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import java.io.File;

import org.junit.Before;
import org.junit.Test;

import cau.se.project.CLSXFile;
import cau.se.project.data.DependencyStructureMatrix;
import cau.se.project.method.CLSXControl;
import cau.se.project.method.FileControl;

public class CLSXFileTest {
	private FileControl clsxFile;
	private File testClusterFile;
	
	@Before
	public void setUp() {
		clsxFile = new CLSXFile(new DependencyStructureMatrix());
		testClusterFile = new File("Test_Cluster_File.clsx");
	}
	
	@Test
	public void testCLSXFile() {
		assertNull(new CLSXFile(new DependencyStructureMatrix()).getCurrentFile());
	}

	@Test
	public void testNewFileOne() throws Exception {
		assertNull(clsxFile.getCurrentFile());
		clsxFile.open(testClusterFile);		
		assertNotNull(clsxFile.getCurrentFile());
		
		clsxFile.newFile();
		assertNull(clsxFile.getCurrentFile());
	}
	
	@Test
	public void testOpenOne() throws Exception {
		assertNull(this.clsxFile.getCurrentFile());
		
		this.clsxFile.open(this.testClusterFile);
		
		assertThat(this.clsxFile.getCurrentFile(), is(this.testClusterFile));
	}
	
	@Test
	public void testOpenTwo() throws Exception {
		assertThat(this.clsxFile.open(testClusterFile).getClass(), is(CLSXControl.class.getClass()));
	}
	
	@Test(expected=Exception.class)
	public void testOpenWithException() throws Exception {
		clsxFile.open(null);
	}

	@Test
	public void testGetCurrentFile() throws Exception {
		assertNull(clsxFile.getCurrentFile());
		clsxFile.open(testClusterFile);
		
		assertThat(clsxFile.getCurrentFile(), is(testClusterFile));
	}

}
